﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Faust.Andrew.MTG.Migration
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            txtSQLCE.Text = Properties.Settings.Default.SQLCe;
            txtSQLite.Text = Properties.Settings.Default.SQLite;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnSQLite_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    txtSQLite.Text = ofd.FileName;
                }
            }
        }

        private void btnSQLCE_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    txtSQLCE.Text = ofd.FileName;
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtSQLCE.Text) || String.IsNullOrEmpty(txtSQLite.Text))
            {
                MessageBox.Show("Must select source and target");
                return;
            }

            Properties.Settings.Default.SQLCe = txtSQLCE.Text;
            Properties.Settings.Default.SQLite = txtSQLite.Text;
            Properties.Settings.Default.Save();

            SqlExpressToSQLite x2l = new SqlExpressToSQLite();
            x2l.Migrate(txtSQLite.Text, txtSQLCE.Text);

            //if (chkFromSQL.Checked)
            //{
            //    SqlExpressToCE x2c = new SqlExpressToCE();
            //    x2c.Migrate(txtSQLite.Text, txtSQLCE.Text);
            //}
            //else
            //{
            //    if (chkDeckOnly.Checked)
            //    {
            //        if (MessageBox.Show("You should only choose the Update Deck option if you are converting to a database that is prepopulated with all Magic Cards. Are you sure you wish to continue?", "Continue?", MessageBoxButtons.YesNo) == DialogResult.No)
            //        {
            //            return;
            //        }
            //    }

            //    SQLiteToCE s2c = new SQLiteToCE();
            //    s2c.Migrate(txtSQLite.Text, txtSQLCE.Text, chkDeckOnly.Checked);
            //}

            MessageBox.Show("Finished Conversion");
        }
    }
}
